package com.campus.client.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.campus.pojos.domain.BillBoard;
import com.campus.pojos.domain.ClientCategory;
import com.campus.result.Result;
import com.campus.service.BillboardService;
import com.campus.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/client/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private BillboardService billboardService;
    @GetMapping("/list")
    public Result<List<ClientCategory>> categoryList(){
        log.info("查询墙分类");
        return Result.success(categoryService.list());
    }


    @GetMapping("/billboard")
    public Result<BillBoard> getNotices() {
        List<BillBoard> list = billboardService.list(new LambdaQueryWrapper<BillBoard>().eq(BillBoard::getShow, true));//查询
        return Result.success(list.get(list.size() - 1));

    }

    /**
     * 根据id查分类名称
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<ClientCategory> getById(@PathVariable Integer id)
    {
        ClientCategory category = categoryService.getById(id);
        return Result.success(category);
    }
}
